<?php
/*
 * @Author: CHINAKAIYUAN<sunkaiyuan@namenode.cn>
 * @Date: 2022-02-18 22:33:04
 * @LastEditTime: 2023-07-02 13:49:01
 * @LastEditors: 孙开源 && sunkaiyuan@namenode.cn
 * @Description: 
 */

namespace App\Models;

class CompanyCategory extends BaseModel
    {
    //
    public $table = "basedata_companycategory";
    protected $guarded = [];
    public function childrentree()
        {
        return $this->hasMany(get_class($this), 'parent_id', 'id')->orderBy("sort", 'asc');
        }
    public function children()
        {
        return $this->childrentree()->with(["children", 'finance', 'department']);
        }
    public function company()
        {
        return $this->hasMany(Company::class);
        }
    public function department()
        {
        return $this->belongsTo(Department::class);
        }
    public function finance()
        {
        return $this->belongsTo(Dic::class, "finance_id", "key")->where(function ($q)
            {
            $q->where("code", 'PartnerType');;
            });
        }
    }